package cxm.exam;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;


import cxm.exam.adapter.DividerItemDecoration;
import cxm.exam.adapter.RecyclerViewListAdapter;
import me.drakeet.meizhi.R;
import me.drakeet.meizhi.data.MeizhiData;
import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


/**
 * Created by ThinkPad on 2017/5/11.
 */

public class MainActivity extends Activity{
    private RecyclerView mRecyclerView;
    private List<String> mDatas;
    final static Gson gson = new GsonBuilder()
            .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
            .serializeNulls()
            .create();
    private Button btnGetMovie;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_main);
        initData();
        mRecyclerView = (RecyclerView)findViewById(R.id.recyclerview);
        btnGetMovie = (Button)findViewById(R.id.getMovie);
        btnGetMovie.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               HttpMethod test = new HttpMethod();
                test.getNews1();
            }
        });
        // 设置布局管理器
       // mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setLayoutManager(new GridLayoutManager(this,4));
        //  设置adapter
        mRecyclerView.setAdapter(new RecyclerViewListAdapter(MainActivity.this,mDatas));
        // 添加分割线
        mRecyclerView.addItemDecoration(new DividerItemDecoration(this,
                DividerItemDecoration.VERTICAL_LIST));
////        // 创建http 客户端
//       OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
////        // 设置连接超时
//        httpClient.connectTimeout(12, TimeUnit.SECONDS);
//        OkHttpClient client = httpClient.build();
//        Retrofit.Builder builder = new Retrofit.Builder();
//        builder.baseUrl("http://gank.io/api/")
//                .client(client)
//                .addConverterFactory(GsonConverterFactory.create(gson));
//        Retrofit gankRest = builder.build();
//        MyGankApi gankService = gankRest.create(MyGankApi.class);
//        // 获取数据
//        Call<MeizhiData> call = gankService.getMeizhiData1(1);
//        call.enqueue(new Callback<MeizhiData>() {
//            @Override
//            public void onResponse(Call<MeizhiData> call, Response<MeizhiData> response) {
//                String success = response.body().toString();
//                MeizhiData test = response.body();
//
//            }
//
//            @Override
//            public void onFailure(Call<MeizhiData> call, Throwable t) {
//                String error = t.getMessage();
//            }
//        });

    }
    // 初始化数据
    private void initData()
    {
        mDatas = new ArrayList<String>();
        for (int i = 'A'; i < 'z'; i++)
        {
            mDatas.add("" + (char) i);
        }
    }
}
